﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace comix
{
    public partial class vitrinacontroll : System.Web.UI.UserControl
    {
        public int ncolumns;
        public BooksCollection bc;

        protected void Page_Load(object sender, EventArgs e)
        {
            Update();
        }

        public void Update()
        {
            if (bc != null)
            {
                int nrows = bc.Items.Count == 0 ? 0 : ((bc.Items.Count - 1) / ncolumns + 1);
                for (int i = 0; i < nrows; i++)
                {
                    TableRow tr = new TableRow();
                    tbl.Rows.Add(tr);
                    string color = (i % 2 == 0) ? "#EEEEEE" : "#DDDDDD"; 
                    for (int j = 0; j < ncolumns; j++)
                    {
                        
                            TableCell tc = new TableCell();
                            tr.Cells.Add(tc);
                            if (ncolumns * i + j < bc.Items.Count)
                            {
                                bookcontrol bk = (bookcontrol)LoadControl("bookcontrol.ascx");
                                bk.book = (Book)bc.Items[i * ncolumns + j];
                                bk.color = color;
                                tc.Controls.Add(bk);
                            }
                            else
                                tc.Width = Unit.Pixel(333);
                    }
                }
            }
        }
    }
}